import { iconfont } from './iconfont'
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { iconDefaultColor } from '../../../configs/skin';
import { Text } from 'react-native';
import { px2dp } from 'rn-xiaobu-utils';

class Icon extends Component {
  render() {
    const { name, size = 24, color = iconDefaultColor } = this.props

    let CustomIcon = iconfont
    if (!CustomIcon) throw new Error('没有找到匹配的font库，请review代码！')
    return (
      <Text style={this.props.style}>
        <CustomIcon color={color} name={name}
          size={px2dp(size)}/>
      </Text>
    )
  }
}

Icon.propTypes = {
  name: PropTypes.string.isRequired,
  size: PropTypes.number,
  color: PropTypes.string,
  style: PropTypes.object
}

export default Icon